﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class web_Controls_ctrl_vl_left_list_vlt_by_nganh : System.Web.UI.UserControl
{
    Common _common = null;
    public string _id = "";
    protected void Page_Load(object sender, EventArgs e)
    {
		
        _common = new Common();
        _id = _common.TextFormat(Request.Params["id"].ToString());
        if (Request.Params["type"] != null)
        {
            if (Request.Params["type"].ToString().Trim().Equals("nganhnghe"))
            {
                LoadTuyendungByNganhnghe(_id);
            }
            if (Request.Params["type"].ToString().Trim().Equals("chucdanh"))
            {
                LoadTuyendungByChucdanh(_id);
            }
        }        
    }
    void LoadTuyendungByNganhnghe(string ma_chuc_danh)
    {
		Page.Title = "Thống kê theo ngành";
        DataTable totalrow = null;
        totalrow = _common.getDataTable("select A.ma_ho_so from ViecLamTrong_yeu_cau_chuyen_mon as A where A.ma_chuyen_mon='"+ma_chuc_danh+"'");

        pagination1.ItemCount = totalrow.Rows.Count;
        SqlParameter[] pa = new SqlParameter[7];
        pa[0] = new SqlParameter("@Tables", "  ViecLamTrong_yeu_cau_chuyen_mon as B inner join ViecLamTrong_ho_so_tuyen_dung as A on A.ma_ho_so = B.ma_ho_so  ");
        pa[1] = new SqlParameter("@PK", "A.ma_ho_so");
        pa[2] = new SqlParameter("@PageNumber", pagination1.CurrentIndex);
        pa[3] = new SqlParameter("@PageSize", pagination1.PageSize);
        pa[4] = new SqlParameter("@Filter", " B.ma_chuyen_mon = '" + ma_chuc_danh + "'");
        pa[5] = new SqlParameter("@Fields", " A.ma_ho_so, A.tieu_de_ho_so, A.so_luong_tuyen, A.luong_tu, A.luong_den, A.mo_ta, A.luong_tu, A.luong_den, convert(varchar, A.ngay_dang, 103) as ngay_dang_vn ");
        pa[6] = new SqlParameter("@Sort", " A.ngay_dang desc ");
        DataTable dt = _common.getDataTable(CommandType.StoredProcedure, "dbo.Paging_SubQuery", pa);
        rpt_list.DataSource = dt;
        rpt_list.DataBind();
    }
    void LoadTuyendungByChucdanh(string ma_chuyen_mon)
    {
		Page.Title = "Thống kê theo chức danh";
        DataTable totalrow = null;
        totalrow = _common.getDataTable("select A.ma_ho_so from ViecLamTrong_ho_so_tuyen_dung as A where A.ma_chuc_danh = '" + ma_chuyen_mon + "'");
        pagination1.ItemCount = totalrow.Rows.Count;
        Page.Title = totalrow.Rows.Count.ToString();
        SqlParameter[] pa = new SqlParameter[7];
        pa[0] = new SqlParameter("@Tables", "  ViecLamTrong_yeu_cau_chuyen_mon as B inner join ViecLamTrong_ho_so_tuyen_dung as A on A.ma_ho_so = B.ma_ho_so ");
        pa[1] = new SqlParameter("@PK", "A.ma_ho_so");
        pa[2] = new SqlParameter("@PageNumber", pagination1.CurrentIndex);
        pa[3] = new SqlParameter("@PageSize", pagination1.PageSize);
        pa[4] = new SqlParameter("@Filter", " A.ma_chuc_danh = '" + ma_chuyen_mon + "'");
        pa[5] = new SqlParameter("@Fields", " A.ma_ho_so, A.tieu_de_ho_so, A.so_luong_tuyen, A.luong_tu, A.luong_den, A.mo_ta, A.luong_tu, A.luong_den, convert(varchar, A.ngay_dang, 103) as ngay_dang_vn ");
        pa[6] = new SqlParameter("@Sort", " A.ngay_dang desc ");
        DataTable dt = _common.getDataTable(CommandType.StoredProcedure, "dbo.Paging_SubQuery", pa);
        rpt_list.DataSource = dt;
        rpt_list.DataBind();
    }
    protected void pagination1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        pagination1.CurrentIndex = currnetPageIndx;
        if (Request.Params["type"].ToString().Trim().Equals("nganhnghe"))
        {
            LoadTuyendungByNganhnghe(_id);
        }
        if (Request.Params["type"].ToString().Trim().Equals("chucdanh"))
        {
            LoadTuyendungByChucdanh(_id);
        }
    }

    protected void rpt_list_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label _lbl_luong = e.Item.FindControl("lbl_luong") as Label;
            DataRowView r = (DataRowView)e.Item.DataItem;
            _lbl_luong.Text = GetLuong(r["luong_tu"].ToString(), r["luong_den"].ToString());
        }
    }
    string GetLuong(string luong_tu, string luong_den)
    {
        string _luong = "";
        if (luong_tu.Trim().Equals("0") && luong_den.Trim().Equals("0"))
        {
            _luong = "Thoả thuận";
        }
        else
        {
            _luong = "Từ " + luong_tu + " đến " + luong_den;
        }
        return _luong;
    }
}
